package com.ruoyi.eqmonitor.smdtv.controller;

import java.util.List;

import com.ruoyi.eqmonitor.smdtv.domain.SmdtvSewage;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtvSewageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

@Api(tags = "污水问题")
@RestController
@RequestMapping("/sewage")
public class SmdtvSewageController extends BaseController{
    
    @Autowired
    private ISmdtvSewageService smdtvSewageService;

    /**
     * 查询污水问题列表
     */
    @GetMapping("/list")
    public TableDataInfo<?> list(SmdtvSewage smdtvSewage){
        if (smdtvSewage.getState() == null){
            startPage();
        }
        List<SmdtvSewage> list = smdtvSewageService.selectSmdtvSewageList(smdtvSewage);
        return getDataTable(list);
    }

    /**
     * 根据id查询污水问题
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(smdtvSewageService.selectSmdtvSewageById(id));
    }

    /**
     * 新增污水问题
     */
    @Log(title = "污水问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmdtvSewage smdtvSewage){
        smdtvSewage.setCreateTime(new Date());
        return toAjax(smdtvSewageService.save(smdtvSewage));
    }

    /**
     * 修改污水问题
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SmdtvSewage smdtvSewage){
        return toAjax(smdtvSewageService.updateById(smdtvSewage));
    }

    /**
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "污水问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(smdtvSewageService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出污水问题列表
     */
    @Log(title = "污水问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmdtvSewage smdtvSewage){
        startPage();
        List<SmdtvSewage> list = smdtvSewageService.selectSmdtvSewageList(smdtvSewage);
        ExcelUtil<SmdtvSewage> util = new ExcelUtil<SmdtvSewage>(SmdtvSewage.class);
        util.exportExcel(response, list, "污水问题数据");
    }
    
}
